import sys
import math
import typing
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5 import QtWidgets


class Background(QGraphicsItem):
    def __init__(self, scene):
        super(Background, self).__init__()
        self.root = QFileInfo(__file__).absolutePath()
        self.bg = QPixmap(self.root + "/res/paper_background.jpg").scaled(1600, 930)
        self.fold = QPixmap(self.root + "/res/fold_shadow.png").scaled(395, 930)
        self.slider_bg = QPixmap(self.root + "/res/time_slider_back.png")
        self.slider = QPixmap(self.root + "/res/time_slider.png")
        self.sliderx = 294

        self.lineH = QPixmap(self.root + "/res/line.png").scaled(1600, 4)
        self.lineV = QPixmap(self.root + "/res/line.png")

        self.scene = scene
        self.scene.addItem(self)

    def boundingRect(self):
        return QRectF(0, 0, self.bg.width(), self.bg.height())

    def paint(self, painter: QPainter, option: 'QStyleOptionGraphicsItem', widget: typing.Optional[QWidget] = ...):
        painter.drawPixmap(0, 0, self.bg)
        painter.drawPixmap(600, 0, self.fold)
        painter.drawPixmap(300, 50, self.slider_bg)
        painter.drawPixmap(self.sliderx, 38, self.slider)
        for i in range(0, 930, 40):
            painter.drawPixmap(0, i, self.lineH)
        for i in range(0, 1600, 40):
            painter.resetTransform()
            painter.translate(i, 0)
            painter.rotate(90)
            painter.drawPixmap(0, 0, self.lineV)

    def updateslider(self):
        self.sliderx += 0.08
        self.update()
